package cn.ickck.law_paper_final.controller;



import cn.ickck.law_paper_final.model.entity.Gdb;
import cn.ickck.law_paper_final.model.entity.GdbBatch;
import cn.ickck.law_paper_final.model.response.GdbBatchResponse;
import cn.ickck.law_paper_final.service.GdbBatchService;
import cn.ickck.law_paper_final.service.GdbService;
import cn.ickck.law_paper_final.utils.*;
import freemarker.template.Configuration;
import freemarker.template.Template;
import freemarker.template.TemplateException;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.util.*;

/**
 * @Author: ck
 * @Description:
 * @Date: Create in 21:34 2020/11/27
 */

@RestController
@RequestMapping("/api/v2/pub/gdb_batch")
public class GdbBatchController {

    @Autowired
    private GdbBatchService gdbBatchService;
    @Autowired
    private GdbService gdbService;


    @RequestMapping("findBatchByPage")
    public JsonData findByPage(Integer page)
    {
        int count =  gdbBatchService.count();

        GdbBatchResponse gdbBatchResponse = new GdbBatchResponse();
        gdbBatchResponse.setCount(count);
        int start = count - page * 20 > 0 ? count - page * 20 : 0;
        int end = count - (page - 1) * 20 > 0 ? count - (page - 1) * 20 : count;

        List<GdbBatch> gdbBatchList = gdbBatchService.selectByPage(start,end);
        gdbBatchResponse.setGdbBatchList(gdbBatchList);


        return JsonData.buildSuccess(gdbBatchResponse);
    }

    @RequestMapping("findByName")
    public JsonData findBatchByName(@Param("page") Integer page, @Param("name") String name) {
        GdbBatchResponse gdbBatchResponse = new GdbBatchResponse();
        List<GdbBatch> gdbBatches = gdbBatchService.findBatchByName(name);
        gdbBatchResponse.setCount(gdbBatches.size());
        List<GdbBatch> gdbBatchList = new ArrayList<>();
        int start = gdbBatches.size() - page * 20 > 0 ? gdbBatches.size() - page * 20 : 0;
        int end = gdbBatches.size() - (page - 1) * 20 > 0 ? gdbBatches.size() - (page - 1) * 20 : gdbBatches.size();
        for (int i = start; i < end; i++) {
            gdbBatchList.add(gdbBatches.get(i));
        }
         gdbBatchResponse.setGdbBatchList(gdbBatchList);
        return JsonData.buildSuccess(gdbBatchResponse);
    }

    @Transactional
    @RequestMapping("deleteById")
    public JsonData deleteById(Integer id)
    {


        Integer flag1 = gdbService.deleteByKey(gdbBatchService.findKeyById(id));
        Integer flag = gdbBatchService.deleteById(id);


        return JsonData.buildSuccess("删除成功");
    }

    @RequestMapping("update")
    public JsonData update(@RequestBody GdbBatch gdbBatch)
    {
        gdbBatchService.update(gdbBatch);
        return JsonData.buildSuccess("更新成功");
    }

    @RequestMapping("exportExcel")
    public void exportExcel(HttpServletResponse httpServletResponse, @RequestBody GdbBatch gdbBatch) throws Exception {
        List<Gdb> gdbList = gdbService.findByNameOrKey(gdbBatch.getKey());
        ExcelUtils.exportExcel(gdbList,Gdb.class, gdbBatch.getName() + ".xlsx", httpServletResponse);
    }

    @RequestMapping("exportZip")
    public void exportZip(HttpServletResponse httpServletResponse, @RequestBody GdbBatch gdbBatch)
    {

        List<Gdb> gdbList = gdbService.findByNameOrKey(gdbBatch.getKey());

        List<File> files = new ArrayList<>();
        for (Gdb gdb : gdbList) {

            Map data = new HashMap<>();
            List<Gdb> gdbList1 = new ArrayList<>();
            gdbList1.add(gdb);
            data.put("Gdbs",gdbList1);

            String filePath = FileUtils.getWordPath();
            //文件唯一名称
            String fileOnlyName = gdb.getName() + UUID.randomUUID().toString() + ".doc";
            /** 生成word  数据包装，模板名，文件生成路径，生成的文件名*/

            WordUtil.createWord(data, "单人强制执行申请书.ftl", filePath, fileOnlyName);
            File f = new File(filePath + File.separator + fileOnlyName);
            files.add(f);
        }

        //调用压缩
        String time = System.currentTimeMillis() + "";
        String zipFilePath = FileUtils.getWordPath() + File.separator + time + ".zip";
        try {
            ZipUtil.create(zipFilePath, files);
            //下载文件
            File f = new File(zipFilePath);
            if (f.exists()) {
                ZipUtil.downloadZip(f, httpServletResponse);
//                DownLoadFileUtil.setResponseHeader(response,zipFilePath);
            } else {
                System.out.println("文件不存在");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

        for (File file : files) {
            file.delete();
        }

    }
    @RequestMapping("exportZip1")
    public void exportZip1(HttpServletResponse httpServletResponse, @RequestBody GdbBatch gdbBatch) {

        List<Gdb> gdbList = gdbService.findByNameOrKey(gdbBatch.getKey());

        List<File> files = new ArrayList<>();
        for (Gdb gdb : gdbList) {

            Map data = new HashMap<>();
            List<Gdb> gdbList1 = new ArrayList<>();
            gdbList1.add(gdb);
            data.put("Gdbs",gdbList1);

            String filePath = FileUtils.getWordPath();
            //文件唯一名称
            String fileOnlyName = gdb.getName() + UUID.randomUUID().toString() + ".doc";
            /** 生成word  数据包装，模板名，文件生成路径，生成的文件名*/

            WordUtil.createWord(data, "诉状（单人）.ftl", filePath, fileOnlyName);
            File f = new File(filePath + File.separator + fileOnlyName);
            files.add(f);
        }

        //调用压缩
        String time = System.currentTimeMillis() + "";
        String zipFilePath = FileUtils.getWordPath() + File.separator + time + ".zip";
        try {
            ZipUtil.create(zipFilePath, files);
            //下载文件
            File f = new File(zipFilePath);
            if (f.exists()) {
                ZipUtil.downloadZip(f, httpServletResponse);
//                DownLoadFileUtil.setResponseHeader(response,zipFilePath);
            } else {
                System.out.println("文件不存在");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

        for (File file : files) {
            file.delete();
        }

    }
    @RequestMapping("exportZip2")
    public void exportZip2(HttpServletResponse httpServletResponse, @RequestBody GdbBatch gdbBatch) {

        List<Gdb> gdbList = gdbService.findByNameOrKey(gdbBatch.getKey());

        List<File> files = new ArrayList<>();
        for (Gdb gdb : gdbList) {

            Map data = new HashMap<>();
            List<Gdb> gdbList1 = new ArrayList<>();
            gdbList1.add(gdb);
            data.put("Gdbs",gdbList1);

            String filePath = FileUtils.getWordPath();
            //文件唯一名称
            String fileOnlyName = gdb.getName() + UUID.randomUUID().toString() + ".doc";
            /** 生成word  数据包装，模板名，文件生成路径，生成的文件名*/

            WordUtil.createWord(data, "双人强制执行申请书.ftl", filePath, fileOnlyName);
            File f = new File(filePath + File.separator + fileOnlyName);
            files.add(f);
        }

        //调用压缩
        String time = System.currentTimeMillis() + "";
        String zipFilePath = FileUtils.getWordPath() + File.separator + time + ".zip";
        try {
            ZipUtil.create(zipFilePath, files);
            //下载文件
            File f = new File(zipFilePath);
            if (f.exists()) {
                ZipUtil.downloadZip(f, httpServletResponse);
//                DownLoadFileUtil.setResponseHeader(response,zipFilePath);
            } else {
                System.out.println("文件不存在");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

        for (File file : files) {
            file.delete();
        }

    }
    @RequestMapping("exportZip3")

    public void exportZip3(HttpServletResponse httpServletResponse, @RequestBody GdbBatch gdbBatch) {

        List<Gdb> gdbList = gdbService.findByNameOrKey(gdbBatch.getKey());

        List<File> files = new ArrayList<>();
        for (Gdb gdb : gdbList) {

            Map data = new HashMap<>();
            List<Gdb> gdbList1 = new ArrayList<>();
            gdbList1.add(gdb);
            data.put("Gdbs",gdbList1);

            String filePath = FileUtils.getWordPath();
            //文件唯一名称
            String fileOnlyName = gdb.getName() + UUID.randomUUID().toString() + ".doc";
            /** 生成word  数据包装，模板名，文件生成路径，生成的文件名*/

            WordUtil.createWord(data, "诉状（双人）.ftl", filePath, fileOnlyName);
            File f = new File(filePath + File.separator + fileOnlyName);
            files.add(f);
        }

        //调用压缩
        String time = System.currentTimeMillis() + "";
        String zipFilePath = FileUtils.getWordPath() + File.separator + time + ".zip";
        try {
            ZipUtil.create(zipFilePath, files);
            //下载文件
            File f = new File(zipFilePath);
            if (f.exists()) {
                ZipUtil.downloadZip(f, httpServletResponse);
//                DownLoadFileUtil.setResponseHeader(response,zipFilePath);
            } else {
                System.out.println("文件不存在");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

        for (File file : files) {
            file.delete();
        }

    }

    @RequestMapping("exportZip4")

    public void exportZip4(HttpServletResponse httpServletResponse, @RequestBody GdbBatch gdbBatch) {

        List<Gdb> gdbList = gdbService.findByNameOrKey(gdbBatch.getKey());

        List<File> files = new ArrayList<>();
        for (Gdb gdb : gdbList) {

            Map data = new HashMap<>();
            List<Gdb> gdbList1 = new ArrayList<>();
            gdbList1.add(gdb);
            data.put("Gdbs",gdbList1);

            String filePath = FileUtils.getWordPath();
            //文件唯一名称
            String fileOnlyName = gdb.getName() + UUID.randomUUID().toString() + ".doc";
            /** 生成word  数据包装，模板名，文件生成路径，生成的文件名*/

            WordUtil.createWord(data, "查封裁定.ftl", filePath, fileOnlyName);
            File f = new File(filePath + File.separator + fileOnlyName);
            files.add(f);
        }

        //调用压缩
        String time = System.currentTimeMillis() + "";
        String zipFilePath = FileUtils.getWordPath() + File.separator + time + ".zip";
        try {
            ZipUtil.create(zipFilePath, files);
            //下载文件
            File f = new File(zipFilePath);
            if (f.exists()) {
                ZipUtil.downloadZip(f, httpServletResponse);
//                DownLoadFileUtil.setResponseHeader(response,zipFilePath);
            } else {
                System.out.println("文件不存在");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

        for (File file : files) {
            file.delete();
        }

    }
    @RequestMapping("exportZip5")
    public void exportZip5(HttpServletResponse httpServletResponse, @RequestBody GdbBatch gdbBatch) {

        List<Gdb> gdbList = gdbService.findByNameOrKey(gdbBatch.getKey());

        List<File> files = new ArrayList<>();
        for (Gdb gdb : gdbList) {

            Map data = new HashMap<>();
            List<Gdb> gdbList1 = new ArrayList<>();
            gdbList1.add(gdb);
            data.put("Gdbs",gdbList1);

            String filePath = FileUtils.getWordPath();
            //文件唯一名称
            String fileOnlyName = gdb.getName() + UUID.randomUUID().toString() + ".doc";
            /** 生成word  数据包装，模板名，文件生成路径，生成的文件名*/

            WordUtil.createWord(data, "无划拨终本模板.ftl", filePath, fileOnlyName);
            File f = new File(filePath + File.separator + fileOnlyName);
            files.add(f);
        }

        //调用压缩
        String time = System.currentTimeMillis() + "";
        String zipFilePath = FileUtils.getWordPath() + File.separator + time + ".zip";
        try {
            ZipUtil.create(zipFilePath, files);
            //下载文件
            File f = new File(zipFilePath);
            if (f.exists()) {
                ZipUtil.downloadZip(f, httpServletResponse);
//                DownLoadFileUtil.setResponseHeader(response,zipFilePath);
            } else {
                System.out.println("文件不存在");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

        for (File file : files) {
            file.delete();
        }

    }
    @RequestMapping("exportZip6")

    public void exportZip6(HttpServletResponse httpServletResponse, @RequestBody GdbBatch gdbBatch) {

        List<Gdb> gdbList = gdbService.findByNameOrKey(gdbBatch.getKey());

        List<File> files = new ArrayList<>();
        for (Gdb gdb : gdbList) {

            Map data = new HashMap<>();
            List<Gdb> gdbList1 = new ArrayList<>();
            gdbList1.add(gdb);
            data.put("Gdbs",gdbList1);

            String filePath = FileUtils.getWordPath();
            //文件唯一名称
            String fileOnlyName = gdb.getName() + UUID.randomUUID().toString() + ".doc";
            /** 生成word  数据包装，模板名，文件生成路径，生成的文件名*/

            WordUtil.createWord(data, "有划拨终本模板.ftl", filePath, fileOnlyName);
            File f = new File(filePath + File.separator + fileOnlyName);
            files.add(f);
        }

        //调用压缩
        String time = System.currentTimeMillis() + "";
        String zipFilePath = FileUtils.getWordPath() + File.separator + time + ".zip";
        try {
            ZipUtil.create(zipFilePath, files);
            //下载文件
            File f = new File(zipFilePath);
            if (f.exists()) {
                ZipUtil.downloadZip(f, httpServletResponse);
//                DownLoadFileUtil.setResponseHeader(response,zipFilePath);
            } else {
                System.out.println("文件不存在");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

        for (File file : files) {
            file.delete();
        }

    }
    @RequestMapping("exportZip7")

    public void exportZip7(HttpServletResponse httpServletResponse, @RequestBody GdbBatch gdbBatch) {

        List<Gdb> gdbList = gdbService.findByNameOrKey(gdbBatch.getKey());

        List<File> files = new ArrayList<>();
        for (Gdb gdb : gdbList) {

            Map data = new HashMap<>();
            List<Gdb> gdbList1 = new ArrayList<>();
            gdbList1.add(gdb);
            data.put("Gdbs",gdbList1);

            String filePath = FileUtils.getWordPath();
            //文件唯一名称
            String fileOnlyName = gdb.getName() + UUID.randomUUID().toString() + ".doc";
            /** 生成word  数据包装，模板名，文件生成路径，生成的文件名*/

            WordUtil.createWord(data, "人缺席无保全-判决书（生意人卡、月利率1.5）.ftl", filePath, fileOnlyName);
            File f = new File(filePath + File.separator + fileOnlyName);
            files.add(f);
        }

        //调用压缩
        String time = System.currentTimeMillis() + "";
        String zipFilePath = FileUtils.getWordPath() + File.separator + time + ".zip";
        try {
            ZipUtil.create(zipFilePath, files);
            //下载文件
            File f = new File(zipFilePath);
            if (f.exists()) {
                ZipUtil.downloadZip(f, httpServletResponse);
//                DownLoadFileUtil.setResponseHeader(response,zipFilePath);
            } else {
                System.out.println("文件不存在");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

        for (File file : files) {
            file.delete();
        }

    }

    @RequestMapping("exportZip8")
    public void exportZip8(HttpServletResponse httpServletResponse, @RequestBody GdbBatch gdbBatch) {

        List<Gdb> gdbList = gdbService.findByNameOrKey(gdbBatch.getKey());

        List<File> files = new ArrayList<>();
        for (Gdb gdb : gdbList) {

            Map data = new HashMap<>();
            List<Gdb> gdbList1 = new ArrayList<>();
            gdbList1.add(gdb);
            data.put("Gdbs",gdbList1);

            String filePath = FileUtils.getWordPath();
            //文件唯一名称
            String fileOnlyName = gdb.getName() + UUID.randomUUID().toString() + ".doc";
            /** 生成word  数据包装，模板名，文件生成路径，生成的文件名*/

            WordUtil.createWord(data, "人到庭有保全-判决书（个人贷款合同、年利率15%）.ftl", filePath, fileOnlyName);
            File f = new File(filePath + File.separator + fileOnlyName);
            files.add(f);
        }

        //调用压缩
        String time = System.currentTimeMillis() + "";
        String zipFilePath = FileUtils.getWordPath() + File.separator + time + ".zip";
        try {
            ZipUtil.create(zipFilePath, files);
            //下载文件
            File f = new File(zipFilePath);
            if (f.exists()) {
                ZipUtil.downloadZip(f, httpServletResponse);
//                DownLoadFileUtil.setResponseHeader(response,zipFilePath);
            } else {
                System.out.println("文件不存在");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

        for (File file : files) {
            file.delete();
        }

    }
    @RequestMapping("exportZip9")
    public void exportZip9(HttpServletResponse httpServletResponse, @RequestBody GdbBatch gdbBatch) {

        List<Gdb> gdbList = gdbService.findByNameOrKey(gdbBatch.getKey());

        List<File> files = new ArrayList<>();
        for (Gdb gdb : gdbList) {

            Map data = new HashMap<>();
            List<Gdb> gdbList1 = new ArrayList<>();
            gdbList1.add(gdb);
            data.put("Gdbs",gdbList1);

            String filePath = FileUtils.getWordPath();
            //文件唯一名称
            String fileOnlyName = gdb.getName() + UUID.randomUUID().toString() + ".doc";
            /** 生成word  数据包装，模板名，文件生成路径，生成的文件名*/

            WordUtil.createWord(data, "人到庭有保全债务分割-判决书（自信一贷，月利率1.1）.ftl", filePath, fileOnlyName);
            File f = new File(filePath + File.separator + fileOnlyName);
            files.add(f);
        }

        //调用压缩
        String time = System.currentTimeMillis() + "";
        String zipFilePath = FileUtils.getWordPath() + File.separator + time + ".zip";
        try {
            ZipUtil.create(zipFilePath, files);
            //下载文件
            File f = new File(zipFilePath);
            if (f.exists()) {
                ZipUtil.downloadZip(f, httpServletResponse);
//                DownLoadFileUtil.setResponseHeader(response,zipFilePath);
            } else {
                System.out.println("文件不存在");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

        for (File file : files) {
            file.delete();
        }

    }
    @RequestMapping("exportZip10")
    public void exportZip10(HttpServletResponse httpServletResponse, @RequestBody GdbBatch gdbBatch) {

        List<Gdb> gdbList = gdbService.findByNameOrKey(gdbBatch.getKey());

        List<File> files = new ArrayList<>();
        for (Gdb gdb : gdbList) {

            Map data = new HashMap<>();
            List<Gdb> gdbList1 = new ArrayList<>();
            gdbList1.add(gdb);
            data.put("Gdbs",gdbList1);

            String filePath = FileUtils.getWordPath();
            //文件唯一名称
            String fileOnlyName = gdb.getName() + UUID.randomUUID().toString() + ".doc";
            /** 生成word  数据包装，模板名，文件生成路径，生成的文件名*/

            WordUtil.createWord(data, "人缺席有结婚证有保全-判决书（生意人卡、月利率1.5）.ftl", filePath, fileOnlyName);
            File f = new File(filePath + File.separator + fileOnlyName);
            files.add(f);
        }

        //调用压缩
        String time = System.currentTimeMillis() + "";
        String zipFilePath = FileUtils.getWordPath() + File.separator + time + ".zip";
        try {
            ZipUtil.create(zipFilePath, files);
            //下载文件
            File f = new File(zipFilePath);
            if (f.exists()) {
                ZipUtil.downloadZip(f, httpServletResponse);
//                DownLoadFileUtil.setResponseHeader(response,zipFilePath);
            } else {
                System.out.println("文件不存在");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

        for (File file : files) {
            file.delete();
        }

    }
    @RequestMapping("exportWord")
    public void exportWord(HttpServletResponse response, @RequestBody GdbBatch gdbBatch)throws Exception
    {

        List<Gdb> gdbList = gdbService.findByNameOrKey(gdbBatch.getKey());

        Map data = new HashMap<>();
        System.out.println("调用方法");

        data.put("Gdbs", gdbList);
        response.setHeader("content-Type", "application/msword");

        // 创建一个FreeMarker实例, 负责管理FreeMarker模板的Configuration实例
        Configuration cfg = new Configuration(Configuration.DEFAULT_INCOMPATIBLE_IMPROVEMENTS);
        // 指定FreeMarker模板文件的位置
        cfg.setClassForTemplateLoading(getClass(), "/templates");
        Template template = null;


        try {
            template = cfg.getTemplate("单人强制执行申请书.ftl", "UTF-8");

        } catch (IOException e) {
            e.printStackTrace();
        }


        OutputStream outputStream = response.getOutputStream();
        OutputStreamWriter outputStreamWriter = new OutputStreamWriter(outputStream);


        try {
            DownLoadFileUtil.setResponseHeader(response, "单人强制执行申请书");
            template.process(data, outputStreamWriter);
//            System.out.println(outputStreamWriter);
        } catch (TemplateException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

    }
    @RequestMapping("exportWord1")
    public void exportWord1(HttpServletResponse response, @RequestBody GdbBatch gdbBatch)throws Exception
    {

        List<Gdb> gdbList = gdbService.findByNameOrKey(gdbBatch.getKey());

        Map data = new HashMap<>();
        System.out.println("调用方法");

        data.put("Gdbs", gdbList);
        response.setHeader("content-Type", "application/msword");

        // 创建一个FreeMarker实例, 负责管理FreeMarker模板的Configuration实例
        Configuration cfg = new Configuration(Configuration.DEFAULT_INCOMPATIBLE_IMPROVEMENTS);
        // 指定FreeMarker模板文件的位置
        cfg.setClassForTemplateLoading(getClass(), "/templates");
        Template template = null;


        try {
            template = cfg.getTemplate("诉状（单人）.ftl", "UTF-8");

        } catch (IOException e) {
            e.printStackTrace();
        }


        OutputStream outputStream = response.getOutputStream();
        OutputStreamWriter outputStreamWriter = new OutputStreamWriter(outputStream);


        try {
            DownLoadFileUtil.setResponseHeader(response, "诉状（单人）");
            template.process(data, outputStreamWriter);
//            System.out.println(outputStreamWriter);
        } catch (TemplateException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

    }
    @RequestMapping("exportWord2")
    public void exportWord2(HttpServletResponse response,@RequestBody GdbBatch gdbBatch)throws Exception
    {
        List<Gdb> gdbList = gdbService.findByNameOrKey(gdbBatch.getKey());

        Map data = new HashMap<>();
        System.out.println("调用方法");

        data.put("Gdbs", gdbList);
        response.setHeader("content-Type", "application/msword");

        // 创建一个FreeMarker实例, 负责管理FreeMarker模板的Configuration实例
        Configuration cfg = new Configuration(Configuration.DEFAULT_INCOMPATIBLE_IMPROVEMENTS);
        // 指定FreeMarker模板文件的位置
        cfg.setClassForTemplateLoading(getClass(), "/templates");
        Template template = null;


        try {
            template = cfg.getTemplate("双人强制执行申请书.ftl", "UTF-8");

        } catch (IOException e) {
            e.printStackTrace();
        }


        OutputStream outputStream = response.getOutputStream();
        OutputStreamWriter outputStreamWriter = new OutputStreamWriter(outputStream);


        try {
            DownLoadFileUtil.setResponseHeader(response, "双人强制执行申请书");
            template.process(data, outputStreamWriter);
//            System.out.println(outputStreamWriter);
        } catch (TemplateException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }


    }
    @RequestMapping("exportWord3")
    public void exportWord3(HttpServletResponse response,@RequestBody GdbBatch gdbBatch)throws Exception
    {
        List<Gdb> gdbList = gdbService.findByNameOrKey(gdbBatch.getKey());

        Map data = new HashMap<>();
        System.out.println("调用方法");

        data.put("Gdbs", gdbList);
        response.setHeader("content-Type", "application/msword");

        // 创建一个FreeMarker实例, 负责管理FreeMarker模板的Configuration实例
        Configuration cfg = new Configuration(Configuration.DEFAULT_INCOMPATIBLE_IMPROVEMENTS);
        // 指定FreeMarker模板文件的位置
        cfg.setClassForTemplateLoading(getClass(), "/templates");
        Template template = null;


        try {
            template = cfg.getTemplate("诉状（双人）.ftl", "UTF-8");

        } catch (IOException e) {
            e.printStackTrace();
        }


        OutputStream outputStream = response.getOutputStream();
        OutputStreamWriter outputStreamWriter = new OutputStreamWriter(outputStream);


        try {
            DownLoadFileUtil.setResponseHeader(response, "诉状（双人）");
            template.process(data, outputStreamWriter);
//            System.out.println(outputStreamWriter);
        } catch (TemplateException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }


    }

    @RequestMapping("exportWord4")
    public void exportWord4(HttpServletResponse response,@RequestBody GdbBatch gdbBatch)throws Exception
    {
        List<Gdb> gdbList = gdbService.findByNameOrKey(gdbBatch.getKey());

        Map data = new HashMap<>();
        System.out.println("调用方法");

        data.put("Gdbs", gdbList);
        response.setHeader("content-Type", "application/msword");

        // 创建一个FreeMarker实例, 负责管理FreeMarker模板的Configuration实例
        Configuration cfg = new Configuration(Configuration.DEFAULT_INCOMPATIBLE_IMPROVEMENTS);
        // 指定FreeMarker模板文件的位置
        cfg.setClassForTemplateLoading(getClass(), "/templates");
        Template template = null;


        try {
            template = cfg.getTemplate("查封裁定.ftl", "UTF-8");

        } catch (IOException e) {
            e.printStackTrace();
        }


        OutputStream outputStream = response.getOutputStream();
        OutputStreamWriter outputStreamWriter = new OutputStreamWriter(outputStream);


        try {
            DownLoadFileUtil.setResponseHeader(response, "查封裁定");
            template.process(data, outputStreamWriter);
//            System.out.println(outputStreamWriter);
        } catch (TemplateException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }


    }
    @RequestMapping("exportWord5")
    public void exportWord5(HttpServletResponse response,@RequestBody GdbBatch gdbBatch)throws  Exception
    {
        List<Gdb> gdbList = gdbService.findByNameOrKey(gdbBatch.getKey());

        Map data = new HashMap<>();
        System.out.println("调用方法");

        data.put("Gdbs", gdbList);
        response.setHeader("content-Type", "application/msword");

        // 创建一个FreeMarker实例, 负责管理FreeMarker模板的Configuration实例
        Configuration cfg = new Configuration(Configuration.DEFAULT_INCOMPATIBLE_IMPROVEMENTS);
        // 指定FreeMarker模板文件的位置
        cfg.setClassForTemplateLoading(getClass(), "/templates");
        Template template = null;


        try {
            template = cfg.getTemplate("无划拨终本模板.ftl", "UTF-8");

        } catch (IOException e) {
            e.printStackTrace();
        }


        OutputStream outputStream = response.getOutputStream();
        OutputStreamWriter outputStreamWriter = new OutputStreamWriter(outputStream);


        try {
            DownLoadFileUtil.setResponseHeader(response, "无划拨终本模板");
            template.process(data, outputStreamWriter);
//            System.out.println(outputStreamWriter);
        } catch (TemplateException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }


    }
    @RequestMapping("exportWord6")
    public void exportWord6(HttpServletResponse response,@RequestBody GdbBatch gdbBatch)throws Exception
    {
        List<Gdb> gdbList = gdbService.findByNameOrKey(gdbBatch.getKey());

        Map data = new HashMap<>();
        System.out.println("调用方法");

        data.put("Gdbs", gdbList);
        response.setHeader("content-Type", "application/msword");

        // 创建一个FreeMarker实例, 负责管理FreeMarker模板的Configuration实例
        Configuration cfg = new Configuration(Configuration.DEFAULT_INCOMPATIBLE_IMPROVEMENTS);
        // 指定FreeMarker模板文件的位置
        cfg.setClassForTemplateLoading(getClass(), "/templates");
        Template template = null;


        try {
            template = cfg.getTemplate("有划拨终本模板.ftl", "UTF-8");

        } catch (IOException e) {
            e.printStackTrace();
        }


        OutputStream outputStream = response.getOutputStream();
        OutputStreamWriter outputStreamWriter = new OutputStreamWriter(outputStream);


        try {
            DownLoadFileUtil.setResponseHeader(response, "有划拨终本模板");
            template.process(data, outputStreamWriter);
//            System.out.println(outputStreamWriter);
        } catch (TemplateException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }


    }
    @RequestMapping("exportWord7")
    public void exportWord7(HttpServletResponse response,@RequestBody GdbBatch gdbBatch)throws Exception
    {
        List<Gdb> gdbList = gdbService.findByNameOrKey(gdbBatch.getKey());

        Map data = new HashMap<>();
        System.out.println("调用方法");

        data.put("Gdbs", gdbList);
        response.setHeader("content-Type", "application/msword");

        // 创建一个FreeMarker实例, 负责管理FreeMarker模板的Configuration实例
        Configuration cfg = new Configuration(Configuration.DEFAULT_INCOMPATIBLE_IMPROVEMENTS);
        // 指定FreeMarker模板文件的位置
        cfg.setClassForTemplateLoading(getClass(), "/templates");
        Template template = null;


        try {
            template = cfg.getTemplate("人缺席无保全-判决书（生意人卡、月利率1.5）.ftl", "UTF-8");

        } catch (IOException e) {
            e.printStackTrace();
        }


        OutputStream outputStream = response.getOutputStream();
        OutputStreamWriter outputStreamWriter = new OutputStreamWriter(outputStream);


        try {
            DownLoadFileUtil.setResponseHeader(response, "人缺席无保全-判决书（生意人卡、月利率1.5）");
            template.process(data, outputStreamWriter);
//            System.out.println(outputStreamWriter);
        } catch (TemplateException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }


    }

    @RequestMapping("exportWord8")
    public void exportWord8(HttpServletResponse response,@RequestBody GdbBatch gdbBatch)throws Exception
    {
        List<Gdb> gdbList = gdbService.findByNameOrKey(gdbBatch.getKey());

        Map data = new HashMap<>();
        System.out.println("调用方法");

        data.put("Gdbs", gdbList);
        response.setHeader("content-Type", "application/msword");

        // 创建一个FreeMarker实例, 负责管理FreeMarker模板的Configuration实例
        Configuration cfg = new Configuration(Configuration.DEFAULT_INCOMPATIBLE_IMPROVEMENTS);
        // 指定FreeMarker模板文件的位置
        cfg.setClassForTemplateLoading(getClass(), "/templates");
        Template template = null;


        try {
            template = cfg.getTemplate("人到庭有保全-判决书（个人贷款合同、年利率15%）.ftl", "UTF-8");

        } catch (IOException e) {
            e.printStackTrace();
        }


        OutputStream outputStream = response.getOutputStream();
        OutputStreamWriter outputStreamWriter = new OutputStreamWriter(outputStream);


        try {
            DownLoadFileUtil.setResponseHeader(response, "人到庭有保全-判决书（个人贷款合同、年利率15%）");
            template.process(data, outputStreamWriter);
//            System.out.println(outputStreamWriter);
        } catch (TemplateException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }


    }
    @RequestMapping("exportWord9")
    public void exportWord9(HttpServletResponse response,@RequestBody GdbBatch gdbBatch)throws Exception
    {
        List<Gdb> gdbList = gdbService.findByNameOrKey(gdbBatch.getKey());

        Map data = new HashMap<>();
        System.out.println("调用方法");

        data.put("Gdbs", gdbList);
        response.setHeader("content-Type", "application/msword");

        // 创建一个FreeMarker实例, 负责管理FreeMarker模板的Configuration实例
        Configuration cfg = new Configuration(Configuration.DEFAULT_INCOMPATIBLE_IMPROVEMENTS);
        // 指定FreeMarker模板文件的位置
        cfg.setClassForTemplateLoading(getClass(), "/templates");
        Template template = null;


        try {
            template = cfg.getTemplate("人到庭有保全债务分割-判决书（自信一贷，月利率1.1）.ftl", "UTF-8");

        } catch (IOException e) {
            e.printStackTrace();
        }


        OutputStream outputStream = response.getOutputStream();
        OutputStreamWriter outputStreamWriter = new OutputStreamWriter(outputStream);


        try {
            DownLoadFileUtil.setResponseHeader(response, "人到庭有保全债务分割-判决书（自信一贷，月利率1.1）");
            template.process(data, outputStreamWriter);
//            System.out.println(outputStreamWriter);
        } catch (TemplateException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }


    }
    @RequestMapping("exportWord10")
    public void exportWord10(HttpServletResponse response,@RequestBody GdbBatch gdbBatch)throws Exception
    {
        List<Gdb> gdbList = gdbService.findByNameOrKey(gdbBatch.getKey());

        Map data = new HashMap<>();
        System.out.println("调用方法");

        data.put("Gdbs", gdbList);
        response.setHeader("content-Type", "application/msword");

        // 创建一个FreeMarker实例, 负责管理FreeMarker模板的Configuration实例
        Configuration cfg = new Configuration(Configuration.DEFAULT_INCOMPATIBLE_IMPROVEMENTS);
        // 指定FreeMarker模板文件的位置
        cfg.setClassForTemplateLoading(getClass(), "/templates");
        Template template = null;


        try {
            template = cfg.getTemplate("人缺席有结婚证有保全-判决书（生意人卡、月利率1.5）.ftl", "UTF-8");

        } catch (IOException e) {
            e.printStackTrace();
        }


        OutputStream outputStream = response.getOutputStream();
        OutputStreamWriter outputStreamWriter = new OutputStreamWriter(outputStream);


        try {
            DownLoadFileUtil.setResponseHeader(response, "人缺席有结婚证有保全-判决书（生意人卡、月利率1.5）");
            template.process(data, outputStreamWriter);
//            System.out.println(outputStreamWriter);
        } catch (TemplateException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }


    }




}
